package com.ecoolex.ying.space.core.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.ecoolex.ying.space.core.pojo.WeiXinProperties;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;

@Configuration
public class WxPayServiceInitializer {

	@Autowired
	private WeiXinProperties weiXinProperties;

	@Bean
	public WxPayConfig wxPayConfig() {
		WxPayConfig payConfig = new WxPayConfig();
		payConfig.setAppId(weiXinProperties.getAppId());
		payConfig.setMchId(weiXinProperties.getMchId());
		payConfig.setMchKey(weiXinProperties.getMchKey());
		payConfig.setNotifyUrl(weiXinProperties.getNotifyUrl());
		payConfig.setKeyPath(weiXinProperties.getKeyPath());
		payConfig.setTradeType("JSAPI");
		payConfig.setSignType("MD5");
		payConfig.setIfSaveApiData(true);
		return payConfig;
	}

	@Bean
	public WxPayService wxPayService(WxPayConfig payConfig) {
		WxPayService wxPayService = new WxPayServiceImpl();
		wxPayService.setConfig(payConfig);
		return wxPayService;
	}
	
}
